<?php

class Controller {
	public $pageTitle = "Moppet";
	public $pageSubtitle = "";
	
	/**
	 * @param string $path
	 * @param array $params
	 * @param string $layoutFile
	 */
	public function render($path, array $params = array(), $layoutFile = "views/layout.php") {
		$file = "views/$path.php";
		if (!file_exists($file)) throw new Exception("View file for '$path' does not exist");
		
		echo $this->getRenderedFile($layoutFile, array(
			'content' => $this->getRenderedFile($file, $params),
		));
	}
	
	private function getRenderedFile($file, array $params = array()) {
		ob_start();
		extract($params);
		include $file;
		return ob_get_clean();
	}
}
